<!DOCTYPE HTML>
<!-- jsdom updates the original file to actually test the setters, per https://github.com/jsdom/jsdom/issues/3732. Also some other minor simplifications. -->
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script>
"use strict";
class TestElement extends HTMLElement {
  constructor() {
    super();
    this.internals = this.attachInternals();
  }
}
customElements.define("test-element", TestElement);
</script>

<test-element id= "testElement"></test-element>

<script>
"use strict";
const element = document.getElementById("testElement");
const properties = [
  "role",
  "ariaActiveDescendantElement",
  "ariaAtomic",
  "ariaAutoComplete",
  "ariaBrailleLabel",
  "ariaBrailleRoleDescription",
  "ariaBusy",
  "ariaChecked",
  "ariaColCount",
  "ariaColIndex",
  // "ariaColIndexText", // tentative -> ElementInternals-accessibility.tentative.html
  "ariaColSpan",
  "ariaControlsElements",
  "ariaCurrent",
  "ariaDescribedByElements",
  // "ariaDescription", // tentative -> ElementInternals-accessibility.tentative.html
  "ariaDetailsElements",
  "ariaDisabled",
  "ariaErrorMessageElements",
  "ariaExpanded",
  "ariaFlowToElements",
  "ariaHasPopup",
  "ariaHidden",
  "ariaInvalid",
  "ariaKeyShortcuts",
  "ariaLabel",
  "ariaLabelledByElements",
  "ariaLevel",
  "ariaLive",
  "ariaModal",
  "ariaMultiLine",
  "ariaMultiSelectable",
  "ariaOrientation",
  "ariaOwnsElements",
  "ariaPlaceholder",
  "ariaPosInSet",
  "ariaPressed",
  "ariaReadOnly",
  "ariaRelevant",
  "ariaRequired",
  "ariaRoleDescription",
  "ariaRowCount",
  "ariaRowIndex",
  // "ariaRowIndexText", // tentative -> ElementInternals-accessibility.tentative.html
  "ariaRowSpan",
  "ariaSelected",
  "ariaSetSize",
  "ariaSort",
  "ariaValueMax",
  "ariaValueMin",
  "ariaValueNow",
  "ariaValueText"
];

for (const property of properties) {
  test(() => {
    assert_inherits(element.internals, property, "defined in ElementInternals");

    assert_equals(element.internals[property], null, "null default value");

    if (property.endsWith("Element")) {
      element.internals[property] = document.body;

      assert_equals(element.internals[property], document.body, "can be set to an Element");
    } else if (property.endsWith("Elements")) {
      const originalArray = [document.body];
      element.internals[property] = originalArray;

      assert_array_equals(element.internals[property], originalArray, "same contents");
      assert_not_equals(element.internals[property], originalArray, "not equal to the original array");
      assert_true(Object.isFrozen(element.internals[property]), "is frozen");
      assert_equals(element.internals[property], element.internals[property], "getter returns the same value");
    } else {
      // It's DOMString?
      element.internals[property] = {
        toString() {
          return "a string";
        }
      };

      assert_equals(element.internals[property], "a string", "can be set to a string");
    }
  }, property);
}
test(() => {
  assert_false("ariaErrorMessageElement" in element.internals);
}, "ariaErrorMessageElement is not defined in ElementInternals");
</script>
